﻿using System;
using System.Data;
using BLL.RF.DiagnoseBottleneck;
using CrystalDecisions.CrystalReports.Engine;

public partial class StatisticData_DiagnoseBottleneck_Production_ForMan_Production_Assemble_ForMan : System.Web.UI.Page
{
    private DateTime dt1
    {
        get { return DateTime.Parse(ViewState["starttime"].ToString()); }
        set { ViewState["starttime"] = value; }
    }
    private DateTime dt2
    {
        get { return DateTime.Parse(ViewState["stoptime"].ToString()); }
        set { ViewState["stoptime"] = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Page.Unload += new EventHandler(Page_Unload);
        }
    }

    void Page_Unload(object sender, EventArgs e)
    {
        this.CrystalReportSource1.Dispose();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        dt1 = DateTime.Parse(this.TextBox1.Value.Trim());
        dt2 = DateTime.Parse(this.TextBox2.Value.Trim());
        BindQCR();
        this.CrystalReportViewer1.Visible = true;
    }

    private void BindQCR()
    {
        this.CrystalReportSource1.ReportDocument.Load(Server.MapPath("Production_ForMan.rpt"));

        TextObject txtTestTime = (TextObject)this.CrystalReportSource1.ReportDocument.ReportDefinition.ReportObjects["Text5"];
        txtTestTime.Text = dt1.ToString() + "-" + dt2.ToString();

        DataSet list = GetQData();
        this.CrystalReportSource1.ReportDocument.SetDataSource(list.Tables[0]);
        this.CrystalReportSource1.DataBind();
        this.CrystalReportViewer1.ReportSource = CrystalReportSource1;
        this.CrystalReportViewer1.DataBind();
    }

    private DataSet GetQData()
    {
        DataSet ds = new DataSet();
        Production_ForMan p = new Production_ForMan();
        ds = p.GetProduction_Assemble(dt1, dt2);
        return ds;
    }
}
